<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>index</title>
</head>

<body>
  <script>
    var getCookie = getCookie('userName');
    console.log(getCookie);

    function setCookie(name, value) {
      var days = 30;
      var exp = new Date();
      exp.setTime(exp.getTime() + days * 60 * 1000);
      document.cookie = name + '=' + escape(value) + ';expires =' + exp.toGMTString();
    }

    function getCookie(cname) {
      var name = cname + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
        }
      }
      return "";
    }
  </script>
</body>

</html>